﻿using Apps.Common;
using Apps.Models;
using System.Linq;
using System.Collections.Generic;
using Apps.Models.PUB;

namespace Apps.BLL.PUB
{
    public partial class PUB_DEV_CAMERABLL
    {

        public override List<PUB_DEV_CAMERAModel> GetListByParentId(ref GridPager pager, string queryStr, object parentId)
        {
            string pid = parentId.ToString();
            var whereLambda = PredicateBuilder.True<PUB_DEV_CAMERA>();

            if (pid != "0")
            {
                whereLambda = whereLambda.And(p => p.NODE_ID == pid);
            }
            if (!string.IsNullOrWhiteSpace(queryStr))
            {
                whereLambda = whereLambda.And(a => (
                         a.NAME.Contains(queryStr)
                                 || a.IP.Contains(queryStr)
                                 || a.USERNAME.Contains(queryStr)
                                 || a.NAME.Contains(queryStr)
                               ));

            }
            IQueryable<PUB_DEV_CAMERA> queryData = m_Rep.GetList().Where(whereLambda.Compile()).AsQueryable();
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
        public override List<PUB_DEV_CAMERAModel> CreateModelList(ref IQueryable<PUB_DEV_CAMERA> queryData)
        {

            List<PUB_DEV_CAMERAModel> modelList = (from r in queryData
                                                   select new PUB_DEV_CAMERAModel
                                                   {
                                                       CAMERA_ID = r.CAMERA_ID,
                                                       NODE_ID = r.NODE_ID,
                                                       MEDIASERVER_ID = r.MEDIASERVER_ID,
                                                       CHANNEL = r.CHANNEL,
                                                       BRAND = r.BRAND,
                                                       TYPE = r.TYPE,
                                                       NAME = r.NAME,
                                                       USERNAME = r.USERNAME,
                                                       PASSWORD = r.PASSWORD,
                                                       IP = r.IP,
                                                       HTTP_PORT = r.HTTP_PORT,
                                                       RTSP_PORT = r.RTSP_PORT,
                                                       SERVER_PORT = r.SERVER_PORT,
                                                       IS_GIS = r.IS_GIS,
                                                       IS_VIEW = r.IS_VIEW,
                                                       IS_ACCESS_TIGER = r.IS_ACCESS_TIGER,
                                                       NET_STATUS = r.NET_STATUS,
                                                       NET_STATUS_TIME = r.NET_STATUS_TIME,
                                                   }).ToList();
            return modelList;
        }
        public override PUB_DEV_CAMERAModel GetById(object id)
        {
            if (IsExists(id))
            {

                PUB_DEV_CAMERA entity = m_Rep.GetById(id);
                PUB_DEV_CAMERAModel model = new PUB_DEV_CAMERAModel();
                model.CAMERA_ID = entity.CAMERA_ID;
                model.NODE_ID = entity.NODE_ID;
                model.MEDIASERVER_ID = entity.MEDIASERVER_ID;
                model.CHANNEL = entity.CHANNEL;
                model.BRAND = entity.BRAND;
                model.TYPE = entity.TYPE;
                model.NAME = entity.NAME;
                model.USERNAME = entity.USERNAME;
                model.PASSWORD = entity.PASSWORD;
                model.IP = entity.IP;
                model.HTTP_PORT = entity.HTTP_PORT;
                model.RTSP_PORT = entity.RTSP_PORT;
                model.SERVER_PORT = entity.SERVER_PORT;
                model.IS_GIS = entity.IS_GIS;
                model.IS_VIEW = entity.IS_VIEW;
                model.IS_ACCESS_TIGER = entity.IS_ACCESS_TIGER;
                model.NET_STATUS = entity.NET_STATUS;
                model.NET_STATUS_TIME = entity.NET_STATUS_TIME;
                return model;
            }
            else
            {
                return null;
            }
        }
    }
}

